package com.dmj.sqldsl.executor.transaction;

import com.dmj.sqldsl.executor.ConnectionManager;
import java.sql.Connection;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class TransactionConnectionManager implements ConnectionManager {

  private ConnectionManager connectionManager;

  public Connection getConnection() {
    if (!TransactionManager.hasTransaction()) {
      return connectionManager.getConnection();
    }
    return TransactionManager.getTransactionConnection(connectionManager::getConnection);
  }
}
